import { createStore, applyMiddleware } from 'redux'
import reducer from './reducer'
import logger from 'redux-logger'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage' //默认存储在localStorage中
// import storage from 'redux-persist/lib/storage/session' //存储在sessionStorage中

import thunk from 'redux-thunk' // 这个插件为了可以在纯函数 js 中可以发请求 

//生成一个持久化的reducer
var persistedReducer = persistReducer( 
    { key:'redux' , storage }, 
    reducer ,
)

//创建store
var store = createStore(persistedReducer, applyMiddleware( thunk,logger, ) )

//生成一个持久化的store
export var persistor = persistStore(store);

export default store;
